package org.btik.light.mobile.common.handler.nbi;

import org.btik.light.meta.event.cmd.DefaultCmd;
import org.btik.light.tool.ByteUtil;

import java.util.HashMap;

/**
 * @author lustre
 * @since 2023/4/30 15:01
 */
public class RawNbiCommand extends DefaultCmd {

    private static final HashMap<String, byte[]> snCache = new HashMap<>();

    private final byte[] command;

    @Override
    public void setTarget(String sn) {
        super.setTarget(sn);
        byte[] bytes = snCache.computeIfAbsent(sn, ByteUtil::u8StrToU8Array);
        System.arraycopy(bytes, 0, command, 6, 12);
    }

    @Override
    public byte[] encode() {
        return command;
    }

    public RawNbiCommand(byte[] command) {
        this.command = command;
    }
}
